
% Capture N images in a loop and measure the elasped time.
% Alert user if sequential images are identical (I.e. capturing faster than the XPlane FPS)

XPIMInit;

N = 500;

previousA = zeros(768, 1024, 3);

tic
for (n=1:N)

  % Capture latest image
  currentA = XPIMCaptureImage();

  % [OPT] Save images to separate files
  %name = 'capture.tif'; % ['capture_', num2str(n), '.tif'];
  %imwrite(currentA, name, 'tif', 'WriteMode', 'overwrite');
  
  % [OPT] Save images to one image file
  %imwrite(currentA, 'capture.tif, 'tif', 'WriteMode', 'append');

  % Check for changes
  if (currentA==previousA)
    disp(["SAME! on frame = ", num2str(n)]);
  end
  previousA = currentA;

  % Do "work"
  sleep(0.02);

end
t = toc

XPIMCleanup();

td = t/N
fps = N/t

%imshow(currentA);
